<template>
<div>
  <!-- <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible"
    > -->
    <!-- <span v-html='text'> -->
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="工单号" prop="workOrderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workOrderNumber" placeholder="请填写工单号" disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设备编码" prop="equipmentCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.equipmentCode" placeholder="请填写设备编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="厂" prop="factory"
                :rules="[
                 ]">
              <el-input v-model="inputForm.factory" placeholder="请填写厂"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="区域" prop="area"
                :rules="[
                 ]">
              <el-input v-model="inputForm.area" placeholder="请填写区域"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="主体设备" prop="mainEquipment"
                :rules="[
                 ]">
              <el-input v-model="inputForm.mainEquipment" placeholder="请填写主体设备"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="检修性质" prop="remarks"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.taskSource" placeholder="请填写任务来源"     ></el-input> -->
              <el-select v-model="inputForm.remarks" placeholder="请填写检修性质" style="width:100%;" >
                <el-option v-for="remarks in $dictUtils.getDictList('repair_nature')" :label="remarks.label" :value="remarks.value" :key="remarks.value"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务来源" prop="taskSource"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.taskSource" placeholder="请填写任务来源"     ></el-input> -->
              <el-select v-model="inputForm.taskSource" placeholder="请填写任务来源" style="width:100%;" >
                <el-option v-for="taskSource in $dictUtils.getDictList('repair_source')" :label="taskSource.label" :value="taskSource.value" :key="taskSource.value"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工内容" prop="roadworkContent"
                :rules="[
                 ]">
              <el-input v-model="inputForm.roadworkContent" placeholder="请填写施工内容"     ></el-input>
           </el-form-item>
        </el-col>
       <!-- <el-col :span="12">
            <el-form-item label="人员选择" prop="unsuccessfulPeople"
                :rules="[
                 ]">
        <user-select :limit='1' :value="inputForm.basicdataPost" @getValue='(value) => {inputForm.basicdataPost=value}' @getUserName='getUserName(name, loginName)'></user-select>
        </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="接办人" prop="unsuccessfulPeople"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.unsuccessfulPeople" placeholder="请填写接办人" disabled=""></el-input> -->
              <user-select :limit='1' :value="inputForm.unsuccessfulPeople" @getValue='(value) => {inputForm.unsuccessfulPeople=value}' @getUserName='getUserName(arguments)'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工号" prop="workNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workNumber" placeholder="请填写工号" disabled=""></el-input>
           </el-form-item>
        </el-col>
	<!-- 	<el-col :span="12">
		            <el-form-item label="检修标准工时" prop="unsuccessfulPeople"
		                :rules="[
		                 ]">
		              <el-input v-model="inputForm.unsuccessfulPeople" placeholder="请填写检修标准工时" disabled=""></el-input>
		           </el-form-item>
		        </el-col>
		        <el-col :span="12">
		            <el-form-item label="检修标准项目承办人数" prop="workNumber"
		                :rules="[
		                 ]">
		              <el-input v-model="inputForm.workNumber" placeholder="请填写检修标准项目承办人数" disabled=""></el-input>
		           </el-form-item>
		        </el-col> -->
        <el-col :span="12">
            <el-form-item label="完成时间" prop="completeTime"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.completeTime" placeholder="请填写完成时间"     ></el-input> -->
              <el-date-picker
                    style="width:100%;"
                    v-model="inputForm.completeTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    default-time="12:00:00">
              </el-date-picker>
           </el-form-item>
        </el-col>
      <!-- <el-col :span="12">
            <el-form-item label="状态" prop="state"
                :rules="[
                 ]">
              <el-select v-model="inputForm.state" placeholder="请填写状态" style="width:100%;" >
                <el-option v-for="state in $dictUtils.getDictList('repair_state')" :label="state.label" :value="state.value" :key="state.value"></el-option>
              </el-select>
           </el-form-item>
        </el-col> -->
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer" style="margin-left: 50%;">
      <!-- <el-button @click="visible = false">关闭</el-button> -->
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  <!-- </el-dialog> -->
  <!-- </span> -->
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          workOrderNumber: '',
          equipmentCode: '',
          factory: '',
          area: '',
          mainEquipment: '',
          taskSource: '',
          roadworkContent: '',
          unsuccessfulPeople: '',
          workNumber: '',
          completeTime: '',
          workTime: '',
          projectMan: '',
          state: 0,
          remarks: '',
          overhaulPeople: '',
          repirpeople: ''
        }
      }
    },
    activated () {
      var date = new Date()
      var time = ''
      var year = date.getFullYear() + ''
      var month = date.getMonth() + 1 + ''
      var strDate = date.getDate() + ''
      for (let i in (date + '').split(' ')[4].split(':')) {
        time = time + (date + '').split(' ')[4].split(':')[i]
      }
      this.inputForm.workOrderNumber = year + month + strDate + time
      this.inputForm.state = 0
    },
    components: {
      UserSelect
    },
    methods: {
      // editState (method, id) {
      //   this.init(method, id)
      // },
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建检修任务分配`
        } else if (method === 'edit' || method === 'editState') {
          this.title = '修改检修任务分配'
        } else if (method === 'view') {
          this.title = '查看检修任务分配'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view' || method === 'editState') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/flowform/form/repairTaskDistribution/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.repairTaskDistribution)
              if (method === 'editState') {
                this.inputForm.state = 1
                this.doSubmit()
              }
              this.loading = false
            })
          }
        })
      },
      // 获取工号值
      getUserName (name) {
        this.inputForm.workNumber = name[1]
        console.log(name)
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$router.push('/flowform/form/RepairTaskDistributionList')
            this.$http({
              url: `/flowform/form/repairTaskDistribution/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
                this.inputForm.id = ''
                this.inputForm.workOrderNumber = ''
                this.inputForm.equipmentCode = ''
                this.inputForm.factory = ''
                this.inputForm.area = ''
                this.inputForm.mainEquipment = ''
                this.inputForm.taskSource = ''
                this.inputForm.roadworkContent = ''
                this.inputForm.unsuccessfulPeople = ''
                this.inputForm.workNumber = ''
                this.inputForm.completeTime = ''
                this.inputForm.state = ''
                this.inputForm.remarks = ''
                var date = new Date()
                var time = ''
                var year = date.getFullYear() + ''
                var month = date.getMonth() + 1 + ''
                var strDate = date.getDate() + ''
                for (let i in (date + '').split(' ')[4].split(':')) {
                  time = time + (date + '').split(' ')[4].split(':')[i]
                }
                this.inputForm.workOrderNumber = year + month + strDate + time
              }
            })
          }
        })
      }
    }
  }
</script>
